package com.hutao.sso.util;

import java.util.ArrayList;
import java.util.List;

public  class  Page<T> {
	
	// 分页时输入的参数
		private int currentPage = 1;      // 当前�?
		private int pageSize = 10;        // 每页显示�?大行�?
		private int pageShow=5;          //每页显示的页�?
		private int rule=pageShow/2;    //标尺
		// 写分页SQL时需要的条件，由输入参数计算而来
		private int begin; // 当前页的起始�?
		// 用于计算总页�?
		private int rows; // 总行�?
		// 总页数，由rows和pageSize计算而来
		private int totalPage;
		
		private List<T> list=new ArrayList<T>();
		
		private T object;
		
		
	 public T getObject() {
			return object;
		}

		public void setObject(T object) {
			this.object = object;
		}

	public int getBegin() {
		
		begin = (currentPage - 1) * pageSize;
		return begin;
	}

	public int getTotalPage() {
		if (rows % pageSize == 0) {
			totalPage = rows / pageSize;
		} else {
			totalPage = rows / pageSize + 1;
		}
		return totalPage;
	}

	public int getCurrentPage() {
		return currentPage;
	}

	public void setCurrentPage(int currentPage) {
		this.currentPage = currentPage;
	}

	public int getPageSize() {
		return pageSize;
	}

	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}

	public int getRows() {
		return rows;
	}

	public void setRows(int rows) {
		this.rows = rows;
		
		/*
		 * 总行数发生改变时,可能引起总页数的变化,
		 * 从�?�可能导致当前页大于总页�?,在此处理�?下这个情�?.
		 * */
		if (currentPage > getTotalPage()) {
			currentPage = getTotalPage();
		}
	}
	
	
	public int getPageShow() {
		return pageShow;
	}

	public int getRule() {
		return rule;
	}

	public List<T> getList() {
		return list;
	}

	public void setList(List<T> list) {
		this.list = list;
	}
}


